﻿using BUS;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectWebBanHang.GUI.Admin
{
    public partial class Index : System.Web.UI.Page
    {
        NguoiDungBUS ndbus = new NguoiDungBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadDSNguoiDung();
            }
        }

        private void LoadDSNguoiDung()
        {
            rpQLUser.DataSource = ndbus.LayDSNguoiDung();
            rpQLUser.DataBind();
        }
        protected void rpQLUser_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName.Equals("UserDetail"))
            {
                int UserId = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("ChiTietTaiKhoan.aspx?UserId=" + UserId);
            }
        }

        protected void rpQLUser_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = (DataRowView)e.Item.DataItem;
                string MaPQ = row["MaPQ"].ToString();

                if (MaPQ == "3")
                {
                    ((Label)e.Item.FindControl("lbStatusEnable")).Text = "Người dùng";
                    ((Label)e.Item.FindControl("lbStatusEnable")).Visible = true;
                }
                else if (MaPQ == "2")
                {
                    ((Label)e.Item.FindControl("lbStatusPendding")).Text = "Thủ kho";
                    ((Label)e.Item.FindControl("lbStatusPendding")).Visible = true;
                }
                else
                {
                    ((Label)e.Item.FindControl("lbStatusDisable")).Text = "Quản trị viên";
                    ((Label)e.Item.FindControl("lbStatusDisable")).Visible = true;
                }
                bool Trangthai = Convert.ToBoolean(row["TrangThai"].ToString());
                if (Trangthai == true)
                {
                    ((Label)e.Item.FindControl("lbStatusActive")).Text = "Đã kích hoạt";
                    ((Label)e.Item.FindControl("lbStatusActive")).Visible = true;
                }
                else
                {
                    ((Label)e.Item.FindControl("lbStatusDelivery")).Text = "Bị khóa";
                    ((Label)e.Item.FindControl("lbStatusDelivery")).Visible = true;
                }

            }
        }
    }
}